import {Form,Row,Col,Select } from 'antd'
import PropTypes from 'prop-types'
// import { routerRedux } from 'dva/router'
const Option = Select.Option
const FormItem = Form.Item



const formItemLayout = {
  labelCol: {
    xs: { span:5},
  },
  wrapperCol: {
    xs: { span: 18 },
  },
}

const YQSelectSearch=({
    // children,
    codeList=[],
    code,
    onFilterChange,
  form: {
    getFieldDecorator,
    getFieldsValue,
    // setFieldsValue,
  },
})=>{

    const handleChange = (key, values) => {
        let fields = getFieldsValue()
        fields[key] = values
        onFilterChange(fields)
      }


    // const {code} = selectFC
    
    return (
        <Row type="flex" justify="start">
            <Col id="selectCode" style={{marginBottom:'10px'}}>
            <FormItem {...formItemLayout}
          label="状态码"
        >
        {getFieldDecorator('code', {initialValue: code})(<Select
            showSearch
            style={{ width: 200 }}
            placeholder="Select a code"
            optionFilterProp="children"
            onChange={handleChange.bind(null,'code')}
            getPopupContainer={() => document.getElementById('selectCode')}
            filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
      >
      {
          codeList.map((s,v)=><Option key={v}>{s}</Option>)
      }
  </Select>)}
  </FormItem>
      </Col>
        </Row>
    )

}

YQSelectSearch.propTypes = {
  form: PropTypes.object,
  // selectFC: PropTypes.object,
  onFilterChange: PropTypes.func,
  }

  export default Form.create()(YQSelectSearch)